package com.flute.icrawler.check.checker;

import java.io.File;
import java.io.FileOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.flute.icrawler.check.util.Util;


public class FileChecker {
	
	private String targetDir = Util.getRootDir("targetFiles") + "/";
	private String sourceDir = Util.getRootDir("CrawlTestFiles") + "/";
	private static Logger logger = LoggerFactory.getLogger("FileChecker");
	
	private int FilesSize = 3;
	
	
	private void compare(){
		for(int i=0;i< FilesSize;i++){
			String strIdFilePath  = i + ".xml";
			File targetFile = new File(targetDir + strIdFilePath);
			File sourceFile = new File(sourceDir + strIdFilePath);
		
			    ICompare compare = new ObjCompare();
				boolean isSame = compare.compare(targetFile,sourceFile); 
				if(!isSame){
					output(strIdFilePath);
				}
		}
		
	}
	private void output(String path){
		
		File file = new File(Util.getRootDir("") + "/different.txt");
		try {
			FileOutputStream out = new FileOutputStream(file,true);
			StringBuffer strbuf = new StringBuffer();
			strbuf.append(path).append(System.getProperty("line.separator"));
			out.write(strbuf.toString().getBytes("utf-8"));
			out.close();
			out = null;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	public static void main(String args[]){
		FileChecker f = new FileChecker();
		f.compare();
		
	}

}
